package com.cyl.manager.act.service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.cyl.manager.act.mapper.FhMapEquipmentrecommendMapper;
import com.cyl.manager.act.domain.entity.FhMapEquipmentrecommend;
import com.cyl.manager.act.domain.query.FhMapEquipmentrecommendQuery;

/**
 * 装备推荐Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class FhMapEquipmentrecommendService {
    @Autowired
    private FhMapEquipmentrecommendMapper fhMapEquipmentrecommendMapper;

    /**
     * 查询装备推荐
     *
     * @param id 装备推荐主键
     * @return 装备推荐
     */
    public FhMapEquipmentrecommend selectById(Integer id) {
        return fhMapEquipmentrecommendMapper.selectById(id);
    }

    /**
     * 查询装备推荐列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 装备推荐
     */
    public List<FhMapEquipmentrecommend> selectList(FhMapEquipmentrecommendQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<FhMapEquipmentrecommend> qw = new QueryWrapper<>();
        qw.eq("del_flag",0);
        Integer fishId = query.getFishId();
        if (fishId != null) {
            qw.eq("fish_id", fishId);
        }
        Integer equipmentId  = query.getEquipmentIds();
        if (equipmentId  != null) {
            //qw.eq("equipment_ids", equipmentIds);
            String condition = "," + equipmentId + ",";
            qw.apply("CONCAT(',', equipment_ids, ',') LIKE {0}", "%" + condition + "%");
        }
        String status = query.getStatus();
        if (!StringUtils.isEmpty(status)) {
            qw.eq("status", status);
        }
        LocalDateTime crateTime = query.getCrateTime();
        if (crateTime != null) {
            qw.eq("crate_time", crateTime);
        }
        return fhMapEquipmentrecommendMapper.selectList(qw);
    }

    /**
     * 新增装备推荐
     *
     * @param fhMapEquipmentrecommend 装备推荐
     * @return 结果
     */
    public int insert(FhMapEquipmentrecommend fhMapEquipmentrecommend) {
        return fhMapEquipmentrecommendMapper.insert(fhMapEquipmentrecommend);
    }

    /**
     * 修改装备推荐
     *
     * @param fhMapEquipmentrecommend 装备推荐
     * @return 结果
     */
    public int update(FhMapEquipmentrecommend fhMapEquipmentrecommend) {
        return fhMapEquipmentrecommendMapper.updateById(fhMapEquipmentrecommend);
    }

    /**
     * 批量删除装备推荐
     *
     * @param ids 需要删除的装备推荐主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return fhMapEquipmentrecommendMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除装备推荐信息
     *
     * @param id 装备推荐主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return fhMapEquipmentrecommendMapper.updateDelFlagByIds(ids);
    }
}
